Component({
  data: {
    current: [],
    options: [],
  },
  methods: {
    msr() {
      let that = this;
      wx.request({
        url: 'http://localhost:8080/ihome/report/list',
        header: {
          'Authorization': 'Bearer ' + wx.getStorageSync('token')
        },
        method: 'GET',
        success(resp) {
          const updatedOptions = resp.data.rows.map(item => ({
            label: item.reportName,
            value: item.id
          }));
          that.setData({
            options: updatedOptions
          });
        },
        fail(error) {
          console.error('请求失败', error);
        }
      });
    },
    handleGroupChange(event) {
      // console.log('group', event.detail.value);
      this.setData({
        current: event.detail.value,
      });
    },
    commitAndBack() {
      const pages = getCurrentPages();
      const currentPage = pages[pages.length - 1]; // 获取当前页面实例
      if (currentPage && currentPage.setReportMeaaage) { // 确保方法名正确
        const selectedOptions = this.data.options.filter(option => this.data.current.includes(option.value));
        currentPage.setReportMeaaage(selectedOptions); // 将选中的 options 传递给方法
      }
      
      wx.navigateBack();
    }
  },

  lifetimes: {
    ready() {
      this.msr(); // 调用 msr 方法以在组件准备好时加载数据
    },
  },
  pageLifetimes: {
    show() {},
    hide() {},
    resize() {},
  },
});
